import { ColumnGroupType, ColumnType } from "antd/es/table"

import { IHandListItemResponse } from "@/api/dxn/type"
import TooltipText from "@/components/common/tooltipText"
import { parseTime } from "@/utils"
import { constant } from "@/utils/const"
import { getCardsName } from "@/utils/tool"
import { getTypeName, handleNumber, handleNumberColor } from "@/utils/util"

import ShowBlindInjection from "../formItems/gameList/showBlindInjection"
import TableContentLink from "../formItems/gameList/tableContentLink"

const GameList = (
	newFormat: (arg: string) => string,
	_getFromDic: (arg: string, strictlyLabel?: boolean) => any
): Record<string, ColumnGroupType<any> | ColumnType<any>> => ({
	handCode: {
		key: "handCode",
		align: "center",
		dataIndex: "handCode",
		title: newFormat("dxn.game_list.hand_id"),
		render: (text: string) =>
			text ? <TableContentLink name={text} to="/dxn/gameManager/gameList/gameBase" queryParams={{ handId: text }} /> : "-",
		width: 190
	},
	handCodeDetail: {
		key: "handCode",
		align: "center",
		dataIndex: "handCode",
		title: newFormat("dxn.game_list.hand_id"),
		width: 190,
		render: (text: string) => text || "-"
	},
	handStatus: {
		key: "handStatus",
		align: "center",
		dataIndex: "handStatus",
		title: newFormat("dxn.card_ables_list.table_state"),
		width: 100,
		render: (text: number) => {
			const statesMap: { [key: number]: string } = {
				0: "进行中",
				1: "已结束",
				2: "异常局"
			}

			return statesMap[text] || "-"
		}
	},
	handListTableCode: {
		key: "tableCode",
		align: "center",
		dataIndex: "tableCode",
		title: newFormat("dxn.card_ables_list.table_id"),
		render: (text: string) =>
			text ? (
				<TableContentLink name={text} to="/dxn/gameManager/cardTablesList/cardTablesBase" queryParams={{ tableId: text }} />
			) : (
				"-"
			),
		width: 180
	},
	handListTableName: {
		key: "tableName",
		align: "center",
		dataIndex: "tableName",
		title: newFormat("dxn.card_ables_list.table_name"),
		width: 200,
		render: (text: string) => text || "-"
	},
	handListTableType: {
		key: "tableType",
		align: "center",
		dataIndex: "tableType",
		title: newFormat("dxn.card_ables_list.game_name"),
		render: _getFromDic("gameType", false),
		width: 100
	},
	handListTableTypes: {
		key: "gameTypeId",
		align: "center",
		dataIndex: "gameTypeId",
		title: newFormat("dxn.card_ables_list.game_name"),
		render: _getFromDic("gameTypes", false),
		width: 100
	},
	specialGameplay: {
		key: "specialPlayType",
		align: "center",
		dataIndex: "specialPlayType",
		title: newFormat("dxn.game_list.special_gameplay"),
		render: (text: number) => getTypeName(text, constant.specialPlayTypeArr),
		width: 120
	},
	squidWinUserName: {
		key: "squidWinUserName",
		align: "center",
		dataIndex: "squidWinUserName",
		title: newFormat("dxn.game_list.squid_gets_players"),
		render: (text: string) => text || "-",
		width: 120
	},
	blindInjection: {
		key: "blindInjection",
		align: "center",
		dataIndex: "blindInjection",
		title: newFormat("dxn.card_ables_list.blind_injection"),
		render: (_: any, record: IHandListItemResponse) => <ShowBlindInjection {...record} />,
		width: 120
	},
	handListClubId: {
		key: "clubId",
		align: "center",
		dataIndex: "clubId",
		title: newFormat("dxn.card_ables_list.club_id"),
		render: (text: string) =>
			text ? <TableContentLink name={text} to="/dxn/clubManager/clubList" queryParams={{ clubId: text }} /> : "-",
		width: 100
	},
	handBeginTime: {
		key: "handBeginTime",
		align: "center",
		dataIndex: "handBeginTime",
		title: newFormat("dxn.card_ables_list.handle_start_time"),
		render: (text: string) => parseTime(text) || "-",
		width: 160
	},
	handEndTime: {
		key: "handEndTime",
		align: "center",
		dataIndex: "handEndTime",
		title: newFormat("dxn.card_ables_list.handle_end_time"),
		render: (text: string) => parseTime(text) || "-",
		width: 160
	},
	handNum: {
		key: "handNum",
		align: "center",
		dataIndex: "handNum",
		width: 80,
		title: newFormat("dxn.card_ables_list.hand_brand"),
		render: (text: string) => text || "-"
	},
	beforeChip: {
		key: "beforeChip",
		align: "center",
		dataIndex: "beforeChip",
		title: newFormat("dxn.game_list.summary_of_open_amount_of_our_bureau"),
		render: (text: string, record: IHandListItemResponse) => handleNumber(record.currency, text),
		width: 150
	},
	bringMidwayChip: {
		key: "bringMidwayChip",
		align: "center",
		dataIndex: "bringMidwayChip",
		title: newFormat("dxn.game_list.summary_of_amounts_brought_in"),
		render: (text: string, record: IHandListItemResponse) => handleNumber(record.currency, text),
		width: 150
	},
	afterChip: {
		key: "afterChip",
		align: "center",
		dataIndex: "afterChip",
		title: newFormat("dxn.game_list.summary_of_closing_balance_of_our_bureau"),
		render: (text: string, record: IHandListItemResponse) => handleNumber(record.currency, text),
		width: 150
	},
	validPot: {
		key: "validPot",
		align: "center",
		dataIndex: "validPot",
		title: newFormat("dxn.game_list.effective_bottom_pool"),
		render: (text: string, record: IHandListItemResponse) => handleNumber(record.currency, text),
		width: 150
	},
	pumpingAmount: {
		key: "pumpingAmount",
		align: "center",
		dataIndex: "pumpingAmount",
		title: newFormat("dxn.card_ables_list.play_cards_pump_water"),
		render: (text: string, record: IHandListItemResponse) => handleNumber(record.currency, text),
		width: 150
	},
	handListInsuredNetAmount: {
		key: "insuredNetAmount",
		title: newFormat("dxn.card_ables_list.classic_insurance_profit_and_loss"),
		dataIndex: "insuredNetAmount",
		align: "center",
		width: 150,
		render: (text: string, record: IHandListItemResponse) => (
			<span style={{ color: handleNumberColor(text as unknown as number) }}>{handleNumber(record.currency, text)}</span>
		)
	},
	evInsuredNetAmount: {
		key: "evInsuredNetAmount",
		title: newFormat("dxn.card_ables_list.ev_insurance_profit_and_loss"),
		dataIndex: "evInsuredNetAmount",
		align: "center",
		width: 150,
		render: (text: string, record: IHandListItemResponse) => handleNumber(record.currency, text)
	},
	handNetAmount: {
		key: "handNetAmount",
		title: newFormat("dxn.card_ables_list.summary_of_member_wins_and_losses"),
		dataIndex: "handNetAmount",
		align: "center",
		width: 150,
		render: (text: string, record: IHandListItemResponse) => (
			<span style={{ color: handleNumberColor(text as unknown as number) }}>{handleNumber(record.currency, text)}</span>
		)
	},
	publicCards: {
		key: "publicCards",
		title: newFormat("dxn.game_list.public_brand_information"),
		dataIndex: "publicCards",
		align: "center",
		width: 120,
		render: (text: string) => (text ? <TooltipText text={getCardsName(text)} /> : "-")
	},
	userNames: {
		key: "userNames",
		title: newFormat("common.member_number"),
		dataIndex: "userNames",
		align: "center",
		width: 120,
		render: (text: string) => (text ? <TooltipText text={text} /> : "-")
	},
	clubName: {
		key: "clubName",
		title: newFormat("dxn.card_ables_list.club_name"),
		dataIndex: "clubName",
		align: "center",
		width: 100,
		render: (text: string) => (text ? <TooltipText text={text} /> : "-")
	},
	nickNames: {
		key: "nickNames",
		title: newFormat("dxn.card_ables_list.member_name"),
		dataIndex: "nickNames",
		align: "center",
		width: 200,
		render: (text: string) => (text ? <TooltipText text={text} /> : "-")
	},
	settleInfo: {
		key: "settleInfo",
		title: newFormat("dxn.game_list.settlement_information"),
		dataIndex: "settleInfo",
		align: "center",
		width: 120,
		render: (text: string) => (text ? <TooltipText text={text} /> : "-")
	},
	handInfos: {
		key: "handInfos",
		title: newFormat("dxn.game_list.start_hand_info"),
		dataIndex: "handInfos",
		align: "center",
		width: 120,
		render: (handInfos: string) => {
			let handsInfoCardsName = ""
			if (handInfos) {
				const handCardsNameArr: string[] = []
				const handInfosArr = handInfos.split(";")
				handInfosArr.forEach(item => {
					const cardsName = getCardsName(item)
					if (cardsName) {
						handCardsNameArr.push(cardsName)
					}
				})
				handsInfoCardsName = handCardsNameArr.join("；")
			}

			return handsInfoCardsName ? <TooltipText text={handsInfoCardsName} /> : "-"
		}
	}
})
export default GameList
